#!/bin/bash

echo "Building the project..."
npm run build

echo "Deploying the application..."
# 假设你的私钥文件路径为/home/yourusername/.ssh/id_rsa，如果在其他位置，请相应更改。
# 删除远程服务器上的旧文件
echo "Delete the old files on the remote server..."
ssh -p 2002 -i ~/.ssh/id_rsa root@ssh.xunxinsoft.com "rm -rf /data/h5/health-cms && mkdir /data/h5/dist"
#ssh -p 2002 -i ~/.ssh/id_rsa root@ssh.xunxinsoft.com "rm -rf /data/h5/health-cms"

# 传输新的应用文件到服务器
echo "Transferring new application files to the server..."
scp -P 2002 -i ~/.ssh/id_rsa -r ./dist root@ssh.xunxinsoft.com:/data/h5
ssh -p 2002 -i ~/.ssh/id_rsa root@ssh.xunxinsoft.com "mv /data/h5/dist /data/h5/health-cms"

#echo "Restart..."
#ssh -p 2002 -i ~/.ssh/id_rsa root@ssh.xunxinsoft.com "pm2 restart health"

echo "Deployment completed successfully."

# 等待用户按任意键后退出
read -p "Press any key to continue . . . " -n1 -s

echo # 产生一个新行
